package week03.holiday;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangxiaokun on 2018/2/8.
 */
public class VacationBuilder implements AbstractBuilder{
    VacationPlanner vacationPlanner ;
    List<DayPlanner> dayPlannerList ;

    @Override
    public void buildDay() {
        vacationPlanner = new VacationPlanner();
        dayPlannerList = vacationPlanner.getDayPlannerList();
    }

    @Override
    public void addDay(){
        dayPlannerList.add(new DayPlanner());
    };

    @Override
    public boolean addHotel(int indexOfDay, String detals) {
        indexOfDay--;   //第几天，客户从1开始计数， 数组从0开始计数
        if (checkIndexOfDay(indexOfDay)) {
            DayPlanner dayPlanner = dayPlannerList.get(indexOfDay);
            dayPlanner.addItem("旅馆", detals);
            return true;
        }
        return false;
    }

    @Override
    public boolean addMeals(int indexOfDay, String detals) {
        indexOfDay--;
        if (checkIndexOfDay(indexOfDay)) {
            DayPlanner dayPlanner = dayPlannerList.get(indexOfDay);
            dayPlanner.addItem("用餐",detals);
            return true;
        }
        return false;
    }

    @Override
    public boolean addSpecalEvert(int indexOfDay, String detals) {
        indexOfDay--;
        if (checkIndexOfDay(indexOfDay)) {
            DayPlanner dayPlanner = dayPlannerList.get(indexOfDay);
            dayPlanner.addItem("特殊活动", detals);
            return true;
        }
        return false;
    }

    @Override
    public boolean addTickets(int indexOfDay, String detals) {
        indexOfDay--;
        if (checkIndexOfDay(indexOfDay)) {
            DayPlanner dayPlanner = dayPlannerList.get(indexOfDay);
            dayPlanner.addItem("公园门票", detals);
            return true;
        }
        return false;
    }

    @Override
    public VacationPlanner getVacationPlanner() {
        return vacationPlanner;
    }

    private boolean checkIndexOfDay(int indexOfDay) {
        return  indexOfDay >= 0 && indexOfDay <= dayPlannerList.size();
    }
}
